"""
与游戏菜单界面相关的模块
"""
import pygame
from src import image, window, process
from src.event import mouse

# “开始冒险”菜单项图片对象
menu_item_start_adventure = None
# “选项”图片对象
setting_options = None


def main_menu_page():
    """
    游戏主菜单界面
    :return:
    """
    draw_bg()
    draw_setting_options()
    draw_menu()


def draw_menu():
    """
    绘制游戏主菜单界面中的菜单
    :return:
    """
    # 菜单项图片在窗口中的位置
    menu_item_position_x = window.WINDOW_WIDTH - image.main_menu_item_start_adventure.get_width() - 60
    menu_item_position_y = 65
    # 创建“开始冒险”菜单项图片对象
    global menu_item_start_adventure
    if menu_item_start_adventure is None:
        menu_item_start_adventure = image.Image(
            img=image.main_menu_item_start_adventure,
            img_active=image.main_menu_item_start_adventure_active,
            position=(menu_item_position_x, menu_item_position_y)
        )
        # 添加事件监听
        menu_item_start_adventure.add_mousemotion_listen()
        menu_item_start_adventure.add_mousedown_listen(menu_item_start_adventure_mousedown_handler)
    # 绘制“开始冒险”菜单项图片
    menu_item_start_adventure.draw()
    pass


def menu_item_start_adventure_mousedown_handler(key, event):
    # 恢复鼠标样式
    mouse.arrow_mouse()
    # 游戏进程状态更新为冒险模式第 1 关
    process.process = process.ADVENTURE001
    # 移除事件监听
    mouse.obj_dict_listen_mousemotion.pop(key, None)
    mouse.obj_dict_listen_mousedown.pop(key, None)


def draw_setting_options():
    """
    绘制游戏主菜单界面的选项
    :return:
    """
    # 创建“选项”图片对象
    global setting_options
    if setting_options is None:
        setting_options = image.Image(
            img=image.setting_options,
            img_active=image.setting_options_active,
            position=(565, 490),
            is_transparent=True
        )
        setting_options.add_mousemotion_listen()
    # 绘制“选项”
    setting_options.draw()


def draw_bg():
    """
    绘制背景图片
    :return:
    """
    # 背景图片缩小为窗口大小
    main_menu_bg = pygame.transform.scale(image.main_menu_bg, window.WINDOW_SIZE)
    # 绘制背景图片
    image.draw_img(main_menu_bg)
